package com.banzhi.shop.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;

import com.banzhi.shop.MyApp;
import com.banzhi.shop.R;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.model.CallBack.PersonDetailCallBack;
import com.banzhi.shop.model.IPersonDetailModel;
import com.banzhi.shop.model.Impl.PersonDetailImpl;
import com.banzhi.shop.utils.ASUtils;
import com.banzhi.shop.utils.Translucent;

import org.json.JSONObject;

import static com.banzhi.shop.MyApp.BlackTiShi;
import static com.banzhi.shop.MyApp.isBlackName;

/**
 * 启动页面
 */
public class QidongActivity extends BaseActivity implements PersonDetailCallBack {
    private IPersonDetailModel personDetailModel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qidong);
        Translucent.setTranslucent(this);
        personDetailModel = new PersonDetailImpl();

        if (ASUtils.isCanUse(MyApp.loginMessage.getString("token", ""))) {
            personDetailModel.getData(this);
        }
        new Handler().postDelayed(new Runnable() {
            public void run() {
                if (!"1".equals(MyApp.loginMessage.getString("isfirst", ""))) {
                    SharedPreferences.Editor editor = MyApp.loginMessage.edit();
                    editor.putString("isfirst", "1");
                    editor.apply();
                /* Create an Intent that will start the Main WordPress Activity. */
                    Intent mainIntent = new Intent(QidongActivity.this, DaohangActivity.class);
                    QidongActivity.this.startActivity(mainIntent);
                    QidongActivity.this.finish();
                } else {
                  //  Intent mainIntent = new Intent(QidongActivity.this, NewLoginActivity.class);
                    Intent mainIntent = new Intent(QidongActivity.this, MainActivity.class);
                    QidongActivity.this.startActivity(mainIntent);
                    QidongActivity.this.finish();
                }
            }
        }, 1500);
    }

    @Override
    public void onChangeDataSuccess(Object object) {

    }

    @Override
    public void onChangeDataError(Object object) {

    }

    @Override
    public void ongetDataSuccess(Object object) {
        isBlackName = 1;
    }

    @Override
    public void ongetDataError(Object object) {
        JSONObject jsonObject = (JSONObject) object;
        isBlackName = 2;
        BlackTiShi = jsonObject.optString("msg");
    }



}
